package com.itheima.myvolatile;

import java.util.LinkedHashMap;

public class 用synchronized解决 {
    public static void main(String[] args) {
        Me m = new Me();
        You y = new You();
        m.setName("我");
        y.setName("你");
        m.start();
        y.start();
    }
}
class Life{
    public static int life = 60;

}
class Me extends Thread{
    @Override
    public void run() {
        synchronized ("1") {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Life.life = 50;
        }
    }
}
class You extends Thread{
    @Override
    public void run() {
        synchronized ("1") {
            while (true) {
                if(Life.life!=60){
                    System.out.println("寿命已经不足60年了");
                    break;
                }
            }
        }
    }
}